package Test1;

public class Add implements ICalculator{
    @Override
    public int calculate(int n, int m) {
        System.out.println("加法");
        return (n+m);
    }
}

class Subtract implements ICalculator{
    @Override
    public int calculate(int n, int m) {
        System.out.print("减法");
        return (n-m);
    }
}
class Multiply implements ICalculator{
    @Override
    public int calculate(int n, int m) {
        System.out.print("乘法");
        return (n*m);
    }
}
class Divide implements ICalculator{
    @Override
    public int calculate(int n, int m) {
        System.out.print("除法");
        return (n/m);
    }
}
class UseCompute {
    public void useCom(ICalculator calc,int one,int two){
        if(calc instanceof Divide){
            if(two==0){
                System.out.println("除数不能为0");
                return;
            }
        }
        int i=calc.calculate(one,two);
        System.out.println(" 计算结果为:"+i);
    }
}
